package com.aiyige.page.my.localVideo;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.aiyige.R;


/**
 * Created by UQIANTU on 16/10/26.
 */

public class NodataView extends FrameLayout {
    private View nodataView;
    private View errorView;
    private ImageView nodataIcon;
    private TextView nodataText;

    private RefreshListener listener;

    public NodataView(Context context) {
        super(context);
        init();
    }

    public NodataView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    private void init() {
        LayoutInflater.from(getContext()).inflate(R.layout.nodata_layout, this);
        nodataView = findViewById(R.id.nodata_layout);
        errorView = findViewById(R.id.error_layout);
        nodataIcon = (ImageView) findViewById(R.id.no_data_icon);
        nodataText = (TextView) findViewById(R.id.no_data_text);
        findViewById(R.id.error_icon).setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                if (null != listener) {
                    listener.onRefresh();
                }
            }
        });
    }

    public void setLearnNoDataView() {
        nodataIcon.setImageResource(R.drawable.ico_nodata_img);
        nodataText.setVisibility(View.GONE);
    }

    public void setNodataText(String text) {
        nodataText.setText(text);
    }

    public void showNodataView() {
        nodataView.setVisibility(View.VISIBLE);
        errorView.setVisibility(View.GONE);
        setVisibility(View.VISIBLE);
    }

    public void showErrorView() {
        errorView.setVisibility(View.VISIBLE);
        nodataView.setVisibility(View.GONE);
        setVisibility(View.VISIBLE);
    }

    public void hideView() {
        errorView.setVisibility(View.GONE);
        nodataView.setVisibility(View.GONE);
        setVisibility(View.GONE);
    }

    public ImageView getNodataIcon() {
        return nodataIcon;
    }

    public void setRefreshListener(RefreshListener listener) {
        this.listener = listener;
    }

    public interface RefreshListener {
        void onRefresh();
    }
}
